<html><head><link href="stylesheets/program.css" rel="stylesheet" title="program" type="text/css" /> <title>Source file</title></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000"><font size="2"><pre><div class="schemedoc-abstract-comment">;;;; This is a demo manual, written to show additional aspects of SchemeDoc.
;;;; In particular Scheme source linking.</div>
<div class="schemedoc-section-comment">;;; Mutatator and Selector functions.</div>
<a name="make-selector-function"></a><div class="schemedoc-definition-comment">;; Returns a function, which selects element number n in a list.
;; The second parameter, which is optional, is used for error message purposes.
;; In general, this parameter should be a string corresponding to the name of the selector function.
;; If the second parameter is given, we check whether the list is long enough for selection.
;; If not, we give a decent error message. We recommend use of the second parameter in order to
;; avoid meaningless error messages.
;; The first element is number 1.
;; (make-selector-function 1) corresponds to car, (make-selector-function 2) corresponds to cadr, etc.
;; .form (make-selector-function n [selector-name])</div><a name="make-selector-function"></a><span><a href="../prog5.html#make-selector-function"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-selector-function n . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">selector-name</span> (<a class="schemedoc-name" href="../../../../../lib/man/general.html#optional-parameter" title="Manual: general">optional-parameter</a> 1 optional-parameter-list #f)))
   (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> selector-name
       (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span>) 
         (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX331" title="R5RS Scheme form">list?</a> lst)
                 (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
		   (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
		       (<a class="schemedoc-name" href="../../../../../lib/man/general.html#display-error" title="Manual: general">display-error</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The selector function " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> selector-name) ": " 
						     "The list "  (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> lst) " is is too short for selection. "
						     "It must have at least " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> n) " elements."
						     ))
		       (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX337" title="R5RS Scheme form">list-ref</a> lst (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))))
               (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="schemedoc-name" href="../../../../../lib/man/general.html#display-error" title="Manual: general">display-error</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The selector function " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> selector-name) ": " 
						   "The parameter  "  (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> lst) "  is supposed to be a list. "
                                                   "In addition, it must have at least "
				                    (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> n) " elements."
						     )))))
       (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span>) (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX337" title="R5RS Scheme form">list-ref</a> lst (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))))

<a name="make-mutator-function"></a><div class="schemedoc-definition-comment">;; Make and return a mutator function which mutates element number n in a list.
;; The returned function takes a list and a new value as arguments.
;; This function takes one optional parameter, which is the name of the mutator
;; This is used for error message purposes.</div><a name="make-mutator-function"></a><span><a href="../prog5.html#make-mutator-function"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(make-mutator-function n . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">mutator-name</span> (<a class="schemedoc-name" href="../../../../../lib/man/general.html#optional-parameter" title="Manual: general">optional-parameter</a> 1 optional-parameter-list)))
   (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> mutator-name
       (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span> <span class="local-name-binding">new-value</span>) 
         (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
            (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
                (<a class="schemedoc-name" href="../../../../../lib/man/general.html#display-error" title="Manual: general">display-error</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "The mutator function " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> mutator-name) ": " 
                                 "The list "  (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> lst) " is is too short for mutator. "
                                 "It must have at least " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> n) " elements."
                               ))
                (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">cons-pair</span> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
                  (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX323" title="R5RS Scheme form">set-car!</a> cons-pair new-value)))))
      (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">lst</span> <span class="local-name-binding">new-value</span>) 
         (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">lgt</span> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX333" title="R5RS Scheme form">length</a> lst)))
            (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> n lgt)
                (<a class="schemedoc-name" href="../../../../../lib/man/general.html#display-error" title="Manual: general">display-error</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> "Error in mutator:"
                                 "The list "  (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> lst) " is is too short for mutator. "
                                 "It must have at least " (<a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> n) " elements."))
                (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">cons-pair</span> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX336" title="R5RS Scheme form">list-tail</a> lst (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1))))
                  (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX323" title="R5RS Scheme form">set-car!</a> cons-pair new-value))))))))

<div class="schemedoc-section-comment">;;; The fac and fib functions.
;;; These functions are found in the source file prog4.scm. 
;;; The manual stuff for these is done via SchemeDoc.
;;; See also &lt;a href="#def"&gt; the other section&lt;/a&gt;.
;;; .section-id abc</div>
<a name="fac"></a><div class="schemedoc-definition-comment">;; Calculate the factorial of n</div><a name="fac"></a><span><a href="../prog5.html#fac"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(fac n)</span>
  (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> 0 n) 1 (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX250" title="R5RS Scheme form">*</a> n (<a class="applied-name" href="prog5-1.html#fac" title="prog5">fac</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)))))

<a name="fib"></a><div class="schemedoc-definition-comment">;; Calculated the fib function.
;; Notice that this is a very inefficient 
;; Implementation.</div><a name="fib"></a><span><a href="../prog5.html#fib"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(fib n)</span>
  (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX118" title="R5RS Scheme form">or</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 0) (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> n 1)) 1)
        (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> (<a class="applied-name" href="prog5-1.html#fib" title="prog5">fib</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 1)) (<a class="applied-name" href="prog5-1.html#fib" title="prog5">fib</a> (<a class="scheme-procedure-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> n 2))))))


<div class="schemedoc-section-comment">;;; A couple of higher order function.
;;; These functions are useful in many situations. You may also 
;;; consult &lt;a href="#abc"&gt; the first section&lt;/a&gt;.
;;; .section-id def</div>
<a name="negate"></a><div class="schemedoc-definition-comment">;; A higher order functions which negates the predicate p. 
;; Negate accepts a predicate and returns the negated predicate.&lt;br&gt;
;; $.parameter In case I need to start this line with a dot, which
;; is not an internal tag.
;; .parameter p A predicate</div><a name="negate"></a><span><a href="../prog5.html#negate"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(negate p)</span>
  (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>) 
    (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (p x) #f #t)))

<a name="compose"></a><div class="schemedoc-definition-comment">;; A higher order function that composes two functions.
;; Returns a function which applies f on g.
;; Both f and g are supposed to take a single argument.
;; .internal-references "section" "abc"
;; .internal-references "section" "SECTION2"
;; .misc Miscelaneous information
;; .comment Internal comment
;; .returns Return value description</div>
<a name="compose"></a><span><a href="../prog5.html#compose"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(compose f g)</span>
  (<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">x</span>)
    (f (g x))))

<div class="schemedoc-section-comment">;;; Another function</div>
<a name="my-as-string"></a><div class="schemedoc-definition-comment">;; An alias of as-string from the general LAML library.</div><a name="my-as-string"></a><span><a href="../prog5.html#my-as-string"><img src="./images/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="http://www.cs.aau.dk/~normark/scheme/distribution/laml/r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">my-as-string</span> <a class="schemedoc-name" href="../../../../../lib/man/general.html#as-string" title="Manual: general">as-string</a>)</pre></font><div>&nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p></div></body></html>